package com.study.product_service.service.impl;

import com.study.product_service.domain.Product;
import com.study.product_service.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: LWM
 * @date: 2019/2/20
 * @time: 10:26
 * Description: No Description
 */
@Service
@Slf4j
public class ProductServiceImpl implements ProductService {
    private static final Map<Integer,Product> daoMap = new HashMap<>();
    static {
        Product p1 = new Product(1,"iphonex",9999,10);
        Product p2 = new Product(1,"冰箱",4000,110);
        Product p3 = new Product(1,"洗衣机",8999,120);
        Product p4 = new Product(1,"电视机",7999,220);

        daoMap.put(p1.getId(),p1);
        daoMap.put(p2.getId(),p2);
        daoMap.put(p3.getId(),p3);
        daoMap.put(p4.getId(),p4);
    }

    @Override
    public List<Product> listProduct() {
        Collection<Product> values = daoMap.values();
        List<Product> products = new ArrayList<>(values);
        return products;
    }

    @Override
    public Product findById(int id) {
        log.info("findById");
        return daoMap.get(id);
    }
}
